package com.ssy.lingxi.order.handler.validator;

import com.ssy.lingxi.common.constant.marketing.ActivityTypeEnum;
import com.ssy.lingxi.order.handler.annotation.InvoiceTypeAnnotation;
import com.ssy.lingxi.order.handler.annotation.PromotionTypeAnnotation;
import com.ssy.lingxi.order.model.constant.InvoiceTypeEnum;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;

/**
 * 营销活动类型校验注解验证类
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-17
 */
public class PromotionTypeValidator implements ConstraintValidator<PromotionTypeAnnotation, Integer> {
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if(value == null) {
            return false;
        }

        return Arrays.stream(ActivityTypeEnum.values()).anyMatch(e -> e.getCode().equals(value));
    }
}
